<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/14
 * Time: 10:26
 */
class MsggHook
{
    const ROUTE_HOOK = 'api/hook/';

    public static function hook()
    {
        $params = array_merge($_GET, $_POST);
        $class = empty($params['class']) ? null : $params['class'];
        $method = empty($params['method']) ? null : $params['method'];
        unset($params['class']);
        unset($params['method']);
        if ($class && $method) {
            try {
                call_user_func(array($class, $method), $params);
            } catch (Exception $e) {
                Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
            }
        }
    }

    public static function getUrl($class, $method, $params = array())
    {
        if (!is_array($params)) {
            $params = array();
        }
        $params['class'] = $class;
        $params['method'] = $method;
        return Yii::app()->createAbsoluteUrl(self::ROUTE_HOOK, $params);
    }

}